package com.yphone.ui.widget;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zzkj.yunphone.R;
import com.yphone.bean.AdBaseInfo;
import com.yphone.tools.GlideManager;
import com.yphone.tools.NiceUtil;

import java.util.ArrayList;
import java.util.List;

public class CardAdvertView extends RelativeLayout implements OnClickListener {
    private static final int NULL_ID = -1;
    private ViewPagerAdapter mAdapter;
    /* access modifiers changed from: private */
    public Callback mCallback;
    /* access modifiers changed from: private */
    public Context mContext;
    private List<AdBaseInfo> mList = new ArrayList();
    private ViewPager mVp;

    public interface Callback {
        void event(int i);
    }

    public class ViewPagerAdapter extends PagerAdapter {
        private List<AdBaseInfo> mList;

        public ViewPagerAdapter(List<AdBaseInfo> list) {
            this.mList = list;
        }

        public int getCount() {
            return this.mList.size();
        }

        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        public Object instantiateItem(ViewGroup container, final int position) {
            View view = LayoutInflater.from(CardAdvertView.this.mContext).inflate(R.layout.item_card_advert, null);
            container.addView(view);
            if (((AdBaseInfo) this.mList.get(position)).ID == -1) {
                ((LinearLayout) view.findViewById(R.id.advert_tv)).setVisibility(GONE);
            } else {
                view.setOnClickListener(new OnClickListener() {
                    public void onClick(View view) {
                        CardAdvertView.this.mCallback.event(position);
                    }
                });
                TextView title = (TextView) view.findViewById(R.id.advert_title_tv);
                TextView info = (TextView) view.findViewById(R.id.advert_info_tv);
                GlideManager.glide(CardAdvertView.this.mContext, (ImageView) view.findViewById(R.id.advert_iv), ((AdBaseInfo) this.mList.get(position)).Img);
                title.setText(((AdBaseInfo) this.mList.get(position)).Title);
                info.setText(((AdBaseInfo) this.mList.get(position)).AdDesc);
            }
            return view;
        }

        public void destroyItem(ViewGroup container, int position, Object object) {
            super.destroyItem(container, position, object);
        }

        public float getPageWidth(int position) {
            return 1.0f;
        }
    }

    public CardAdvertView(Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public CardAdvertView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView();
    }

    public CardAdvertView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    public void setData(List<AdBaseInfo> list) {
        if (list != null) {
            this.mList.clear();
            this.mList.addAll(list);
            this.mAdapter.notifyDataSetChanged();
        }
    }

    public void setListener(Callback callback) {
        this.mCallback = callback;
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_card_advert, this);
        this.mVp = (ViewPager) findViewById(R.id.card_advert_vp);
        initListener();
        this.mVp.setPageMargin(NiceUtil.dp2px(this.mContext, 15.0f));
        this.mVp.setOffscreenPageLimit(6);
        AdBaseInfo info = new AdBaseInfo();
        info.ID = -1;
        this.mList.add(info);
        this.mAdapter = new ViewPagerAdapter(this.mList);
        this.mVp.setAdapter(this.mAdapter);
    }

    private void initListener() {
    }

    public void onClick(View v) {
    }
}